package com.aaa.statistics.service.impl;



import com.aaa.entity.HisRegistration;
import com.aaa.statistics.dao.WorkloadDao;
import com.aaa.statistics.service.IRegistrationService;
import com.aaa.statistics.vo.HisRegistrationSaleVo;
import com.aaa.statistics.vo.HisRegistrationVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aaa.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chengchenchen
 * @since 2023-04-01
 */
@Service
public class RegistrationServiceImpl extends ServiceImpl<WorkloadDao, HisRegistration> implements IRegistrationService {
    @Autowired
    private WorkloadDao workloadDao;

    /**
     * 查询所有医生的工作量
     * @param
     * @return
     */
    @Override
    public Result<IPage<HisRegistration>> queryAll(Integer currentPage, Integer pageSize,HisRegistrationVo hisRegistrationVo) {
        IPage<HisRegistration> page=new Page<>(currentPage,pageSize);
        QueryWrapper<HisRegistration> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(hisRegistrationVo.getDoctorName())) {
            wrapper.like("doctor_name", hisRegistrationVo.getDoctorName());
        }
        if (Objects.nonNull(hisRegistrationVo.getDateRange()) && hisRegistrationVo.getDateRange().length == 2) {
            wrapper.between("visit_date", hisRegistrationVo.getDateRange()[0], hisRegistrationVo.getDateRange()[1]);
        } else {
            LocalDateTime now = LocalDateTime.now();
            String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            wrapper.like("visit_date", format);//默认当前时间
        }
        IPage<HisRegistration> registrationList = workloadDao.selectPage(page,wrapper);
        return new Result<>(2000, "查询所有医生的工作量信息成功", registrationList);
    }

    /**
     * 查询医生总体工作量
     * @param
     * @return
     */
    @Override
    public Result<List<HisRegistrationSaleVo>> querySata(HisRegistrationVo hisRegistrationVo) {
        List<HisRegistrationSaleVo> registrationSaleVoList = workloadDao.querySata(hisRegistrationVo);
        return new Result<>(2000,"查询医生总体工作量信息成功",registrationSaleVoList);
    }
}
